package meijuli.com.join51.business.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import meijuli.com.join51.business.R;
import meijuli.com.join51.business.fragment.FindPwdFragment;
import meijuli.com.join51.business.fragment.LoginFragment;
import meijuli.com.join51.business.model.AppBean;
import meijuli.com.join51.business.utils.UpdateCheck;

/**
 * 登录页面
 *
 * @author wenqin 2017-04-13 16:27
 */
public class LoginActivity extends BaseActivity {
    public static final String KEY_STATUS = "status";
    public static final int TO_FIND_PW = 1;

    public static void start(Activity activity, int status) {
        Intent intent = new Intent(activity, LoginActivity.class);
        intent.putExtra(KEY_STATUS, status);
        activity.startActivity(intent);
    }


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_fragment);
        int status = getIntent().getIntExtra(KEY_STATUS, 0);
        if (savedInstanceState == null) {
            switch (status) {
                case TO_FIND_PW:
                    FindPwdFragment findPwdFragment = new FindPwdFragment();
                    addFragment(findPwdFragment);
                    break;
                default:
                    LoginFragment loginFragment = new LoginFragment();
                    addFragment(loginFragment);
                    break;
            }
        }
        checkUpdate();
    }

    private void checkUpdate() {
        UpdateCheck.getUpdateCheck().setUpdateCheckListener(new UpdateCheck.OnUpdateCheckListener() {
            @Override
            public void onUpdateCheckStart() {

            }

            @Override
            public void onUpdateCheckComplete(AppBean appBean, String currentVersion) {

            }

            @Override
            public void onUpdateCheckNew() {
            }

            @Override
            public void onUpdateCheckFail() {

            }
        }).check();
    }

    @Override
    public void onBackPressed() {
        if (!getSupportFragmentManager().popBackStackImmediate()) {
            super.onBackPressed();
        }
    }

}
